package com.watson.juc.testlist;

import java.util.Arrays;
import java.util.List;

/**
 * 要求;一分钟内完成此题，只熊用一行代码实斑!
 * 现在有5个用广!筛选;
 * 1、ID必须是偶数
 * 2、年彩必领人于23
 * 3、用户名转为大写字母
 * 4、用户名字母倒徘序
 * 5、只输出一个用户!
 **/
public class StreamTest {
    public static void main(String[] args) {
        User u1 = new User(1, "a", 22);
        User u2 = new User(2, "b", 22);
        User u3 = new User(3, "c", 23);
        User u4 = new User(4, "d", 24);
        User u5 = new User(5, "e", 25);

        List<User> list = Arrays.asList(u1, u2, u3, u4, u5);
        list.stream()
                .filter(user -> {
                    return user.getAge() > 23;
                })
                .filter(user -> {
                    return user.getId() % 2 == 0;
                })
                .map(user -> {
                    // map 转换 默认是
                    return user.getName().toUpperCase();
                })
//                .sorted()
                .sorted((uu1, uu2) -> {
                    return uu1.compareTo(uu2);   //正序
//                    return uu2.compareTo(uu1);   //倒序
                })
                .limit(1)
                .forEach(System.out::println);
    }
}

class User {
    int id;
    int age;
    String name;

    public User(int id, String name, int age) {
        this.id = id;
        this.age = age;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
